home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / ASCII.H < prev    next >
C/C++ Source or Header  |  1987-03-04  |  5KB  |  109 lines

  1. /*  File   : strings.d/ascii.h
  2.     Author : Richard A. O'Keefe
  3.     Updated: 28 April 1984
  4.     Purpose: Define Ascii mnemonics.
  5.  
  6.     This file defines the ASCII control characters.  Note that these
  7.     names refer to their use in communication; it is an ERROR to use
  8.     these names to talk about keyboard commands.  For example, DO NOT
  9.     use EOT when you mean "end of file", as many people prefer ^Z (if
  10.     the Ascii code were taken seriously, EOT would log you off and
  11.     hang up the line as well).  Similarly, DO NOT use DEL when you
  12.     mean "interrupt", many people prefer ^C.  When writing a screen
  13.     editor, you should speak of tocntrl('C') rather than ETX (see the
  14.     header file "ctypes.h").
  15. */
  16.  
  17. #define NUL    '\000'  /* null character */
  18. #define SOH    '\001'  /* Start Of Heading, start of message */
  19. #define STX    '\002'  /* Start Of Text, end of address */
  20. #define ETX    '\003'  /* End of TeXt, end of message */
  21. #define EOT    '\004'  /* End Of Transmission */
  22. #define ENQ    '\005'  /* ENQuiry "who are you" */
  23. #define ACK    '\006'  /* (positive) ACKnowledge */
  24. #define BEL    '\007'  /* ring the BELl */
  25. #define BS     '\010'  /* BackSpace */
  26. #define HT     '\011'  /* Horizontal Tab */
  27. #define TAB    '\011'  /* an unofficial name for HT */
  28. #define LF     '\012'  /* Line Feed (does not imply cr) */
  29. #define NL     '\012'  /* unix unofficial name for LF: new line */
  30. #define VT     '\013'  /* Vertical Tab */
  31. #define FF     '\014'  /* Form Feed (new page starts AFTER this) */
  32. #define CR     '\015'  /* Carriage Return */
  33. #define SO     '\016'  /* Shift Out; select alternate character set */
  34. #define SI     '\017'  /* Shift In; select ASCII again */
  35. #define DLE    '\020'  /* Data Link Escape */
  36. #define DC1    '\021'  /* Device Control 1 */
  37. #define XON    '\021'  /* transmitter on, resume output */
  38. #define DC2    '\022'  /* Device Control 2 (auxiliary on) */
  39. #define DC3    '\023'  /* Device Control 3 */
  40. #define XOFF   '\023'  /* transmitter off, suspend output */
  41. #define DC4    '\024'  /* Device Control 4 (auxiliary off) */
  42. #define NAK    '\025'  /* Negative AcKnowledge (signal error) */
  43. #define SYN    '\026'  /* SYNchronous idle */
  44. #define ETB    '\027'  /* End of Transmission Block, logical end of medium */
  45. #define CAN    '\030'  /* CANcel */
  46. #define EM     '\031'  /* End of Medium */
  47. #define SUB    '\032'  /* SUBstitute */
  48. #define ESC    '\033'  /* ESCape */
  49. #define FS     '\034'  /* File Separator */
  50. #define GS     '\035'  /* Group Separator */
  51. #define RS     '\036'  /* Record Separator */
  52. #define US     '\037'  /* Unit Separator */
  53. #define SP     '\040'  /* SPace */
  54. #define DEL    '\177'  /* DELete, rubout */
  55.               SHAR_EOF
  56. sed 's/^X//' << 'SHAR_EOF' > bcmp.c
  57. /*  File   : bcmp.c
  58.     Author : Richard A. O'Keefe.
  59.     Updated: 23 April 1984
  60.     Defines: bcmp()
  61.  
  62.     bcmp(s1, s2, len) returns 0 if the "len" bytes starting at "s1" are
  63.     identical to the "len" bytes starting at "s2", non-zero if they are
  64.     different.   The 4.2bsd manual page doesn't say what non-zero value
  65.     is returned, though the BUGS note says that it takes its parameters
  66.     backwards from strcmp.  This suggests that it is something like
  67.        for (; --len >= 0; s1++, s2++)
  68.            if (*s1 != *s2) return *s2-*s1;
  69.        return 0;
  70.     There, I've told you how to do it.  As the manual page doesn't come
  71.     out and *say* that this is the result, I tried to figure out what a
  72.     useful result might be.   (I'd forgotten than strncmp stops when it
  73.     hits a NUL, which the above does not do.)  What I came up with was:
  74.     the result is the number of bytes in the differing tails.  That is,
  75.     after you've skipped the equal parts, how many characters are left?
  76.     To put it another way, N-bcmp(s1,s2,N) is the number of equal bytes
  77.     (the size of the common prefix).  After deciding on this definition
  78.     I discovered that the CMPC3 instruction does exactly what I wanted.
  79.     The code assumes that N is non-negative.
  80.  
  81.     Note: the "b" routines are there to exploit certain VAX order codes,
  82.     but the CMPC3 instruction will only test 65535 characters.   The asm
  83.     code is presented for your interest and amusement.
  84. */
  85.  
  86. #include "strings.h"
  87.  
  88. #if    VaxAsm
  89.  
  90. int bcmp(s1, s2, len)
  91.     char *s1, *s2;
  92.     int len;
  93.     {
  94.        asm("cmpc3 12(ap),*4(ap),*8(ap)");
  95.     }
  96.  
  97. #else  ~VaxAsm
  98.  
  99. int bcmp(s1, s2, len)
  100.     register char *s1, *s2;
  101.     register int len;
  102.     {
  103.        while (--len >= 0 && *s1++ == *s2++) ;
  104.        return len+1;
  105.     }
  106.  
  107. #endif VaxAsm
  108.  
  109.